home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_09 / welstead / cwlstdlg.cpp < prev    next >
C/C++ Source or Header  |  1995-05-20  |  5KB  |  151 lines

  1. // CWLSTDLG.CPP  List Dialogs
  2.  
  3. #include "cwdlg.h"
  4. #include "dlgids.h"
  5.  
  6. tlist_dialog *this_list_dialog = 0;
  7.  
  8. BOOL CALLBACK _export tlist_dialog_proc(HWND hdlg,
  9.         UINT message,WPARAM wParam, LPARAM lParam) {
  10.     return this_list_dialog->handle_message(hdlg,
  11.         message,wParam,lParam); }
  12.  
  13. tlist_dialog::tlist_dialog (HWND Parent,
  14.       LPCSTR caption_name,LPCSTR descr_name,
  15.       tlist_box_data *the_data_rec,int init_selected):
  16.       tdialog (Parent,"LIST_DIALOG",caption_name) {
  17.     list_box_descr = descr_name;
  18.     selected = init_selected;
  19.     list_box_data = the_data_rec; }
  20.  
  21. BOOL tlist_dialog::respond_wm_initdialog () {
  22.     SetWindowText (hdialog,caption_title);
  23.     SetWindowText (GetDlgItem(hdialog,ID_LSTDIALG_DESCR),
  24.      list_box_descr);
  25.     set_data (list_box_data);
  26.     SetFocus(GetDlgItem(hdialog,ID_LSTDIALG_LSTBOX));
  27.     return tdialog::respond_wm_initdialog () ; }
  28.  
  29. BOOL tlist_dialog::respond_wm_command (WPARAM wParam,
  30.       LPARAM lParam) {
  31.     switch (LOWORD(wParam)) {
  32.     case IDOK:
  33.          selected = (int)SendDlgItemMessage(hdialog,
  34.         ID_LSTDIALG_LSTBOX,LB_GETCURSEL,0,0L) + 1;
  35.      dlg_return_value = 1;
  36.      EndDialog(hdialog, TRUE);
  37.      return 1;
  38.     case IDCANCEL:
  39.          dlg_return_value = 0;
  40.      EndDialog(hdialog,FALSE);
  41.     case ID_LSTDIALG_LSTBOX:
  42.             switch (GET_WM_COMMAND_CMD(wParam,lParam)) {
  43.      case LBN_DBLCLK:
  44.             selected = (int)SendDlgItemMessage(hdialog,
  45.             ID_LSTDIALG_LSTBOX,LB_GETCURSEL,0,0L) + 1;
  46.             dlg_return_value = 1;
  47.           EndDialog(hdialog, TRUE);
  48.           return 1;
  49.            }  // end switch
  50.      }  // end switch  
  51.      return 0; }
  52.  
  53. void tlist_dialog::set_data (tlist_box_data *data_rec){
  54.     int i;
  55.     data_rec->selected_item = selected;
  56.     clear_list_box();
  57.     for (i=1;i<=(data_rec->item_collection)->
  58.             get_count();i++)  
  59.     SendDlgItemMessage(hdialog,ID_LSTDIALG_LSTBOX,
  60.         LB_ADDSTRING,0,(LRESULT)get_item_string(i));
  61.     set_selected(selected); }
  62.  
  63. void tlist_dialog::get_data (tlist_box_data *data_rec){
  64.     // All we care about is getting the selected item
  65.     // index. The object list updates itself.
  66.     data_rec->selected_item = selected; }
  67.  
  68. LPSTR tlist_dialog::get_item_string (int item) {
  69.     // Assumes item_collection in list_box_data is an
  70.     // array of strings. Override this for list boxes
  71.     // with more complex items.
  72.     return (LPSTR)((list_box_data->
  73.        item_collection)->at(item)); }
  74.  
  75. void tlist_dialog::set_selected (int sel) {
  76.     SendDlgItemMessage(hdialog,ID_LSTDIALG_LSTBOX,
  77.        LB_SETCURSEL,sel-1, 0); }
  78.  
  79. void tlist_dialog::clear_list_box () {
  80.     SendDlgItemMessage(hdialog,ID_LSTDIALG_LSTBOX,
  81.        LB_RESETCONTENT,0, 0); }
  82.  
  83. BOOL tlist_dialog::exec_dialog () {
  84.     if (!check_gdlg_instance()) return 0;
  85.     tlist_dialog *old_tlist_dialog = this_list_dialog;
  86.     this_list_dialog = this;
  87.     lpDialogProc =
  88.     (DLGPROC)MakeProcInstance(
  89.     (FARPROC)tlist_dialog_proc,gdlg_instance);
  90.     DialogBox(gdlg_instance,rc_title, hwndParent,
  91.        lpDialogProc);
  92.     FreeProcInstance((FARPROC)lpDialogProc);
  93.     this_list_dialog = old_tlist_dialog;
  94.     return dlg_return_value; }
  95.  
  96. tlist_dialog::~tlist_dialog () {
  97.      clear_list_box(); }
  98.  
  99. tdata_list_dialog *this_data_list_dialog = 0;
  100.  
  101. BOOL CALLBACK _export tdata_list_dialog_proc(HWND
  102.      hdlg, UINT message,WPARAM wParam, LPARAM lParam){
  103.     return this_data_list_dialog->handle_message(hdlg,
  104.         message,wParam,lParam); }  
  105.  
  106. LPSTR tdata_list_dialog::get_item_string (int item) {
  107.     return (LPSTR)
  108.      (((ttyped_data_obj *)((list_box_data->
  109.     item_collection)->at(item)))->
  110.         get_display_str()); }
  111.  
  112. BOOL tdata_list_dialog::respond_wm_command
  113.           (WPARAM wParam,LPARAM lParam) {
  114.      int list_selected;
  115.  
  116.      switch (LOWORD(wParam)) {
  117.      case ID_LSTDIALG_LSTBOX:
  118.             switch (GET_WM_COMMAND_CMD(wParam,lParam)) {
  119.      case LBN_DBLCLK:
  120.          list_selected = (int)SendDlgItemMessage(
  121.         hdialog,ID_LSTDIALG_LSTBOX,LB_GETCURSEL,
  122.         0,0L) + 1;
  123.         ((ttyped_data_obj *)((list_box_data->
  124.           item_collection)->at(list_selected)))->
  125.           get_new_value(hdialog,MAX_DISPLAY_LEN);
  126.         list_box_data->selected_item =
  127.           list_selected;
  128.         set_data (list_box_data);
  129.         SetFocus(GetDlgItem(hdialog,
  130.           ID_LSTDIALG_LSTBOX));
  131.         return 1;
  132.             }  // end switch
  133.     }  /* end switch  */
  134.     return tlist_dialog::respond_wm_command(wParam,lParam); }
  135.  
  136. BOOL tdata_list_dialog::exec_dialog () {
  137.     if (!check_gdlg_instance()) return 0;
  138.     tdata_list_dialog *old_data_list_dialog =
  139.          this_data_list_dialog;
  140.     this_data_list_dialog = this;
  141.     lpDialogProc =
  142.     (DLGPROC)MakeProcInstance(
  143.     (FARPROC)tdata_list_dialog_proc,gdlg_instance);
  144.     DialogBox(gdlg_instance,rc_title, hwndParent,
  145.        lpDialogProc);
  146.     FreeProcInstance((FARPROC)lpDialogProc);
  147.     this_data_list_dialog = old_data_list_dialog;
  148.     return dlg_return_value; }
  149.  
  150.  
  151.